RestServiceClientHelper

open class RestServiceClientHelper(var host: String, trustAllCertificates: Boolean, var defaultHeaders: NameValuePair)

Класс, от которого наследуются тестовые клиенты к rest-сервисам. Предоставляет методы, с помощью которых можно отправлять запросы к сервисам.

Примеры:

public class RestClient extends RestServiceClientHelper {
public RestClient(String host) { super(host); }

public RestResponse<Response> getMethod() {
return sendGetRequest(Response.class, "v2/api/get/method");
}
}
public class RestClient extends RestServiceClientHelper {
public RestClient(String host) { super(host, new BasicHeader("headerName", "value")); }

public RestResponse<Response> postMethod(Request request) {
return sendPostRequest(Response.class, "v2/api/post/method", request);
}

public RestResponse<Response> getMethod() {
return sendGetRequest(Response.class, "v2/api/get/method");
}
}
public class RestClient extends RestServiceClientHelper {
public RestClient(String host) {
super(host, new BasicHeader("headerName1", "value1"), new BasicHeader("headerName2", "value2"));
}

public RestResponse<Response> postMethod(Request request, Boolean needThrow) throws RestException {
return sendPostRequest(needThrow, Response.class, "v2/api/post/method", request);
}
}

Constructors

Link copied to clipboard
constructor(host: String, vararg defaultHeaders: NameValuePair)

Конструктор класса

constructor(host: String, sslContext: SSLContext, vararg defaultHeaders: NameValuePair)

Конструктор класса

constructor(host: String, httpClientBuilderFunc: (HttpClientBuilder) -> HttpClientBuilder, vararg defaultHeaders: NameValuePair)

Конструктор класса.

constructor(host: String, trustAllCertificates: Boolean, vararg defaultHeaders: NameValuePair)

Конструктор класса

Properties

Link copied to clipboard
private var defaultHeaders: Array<out NameValuePair>

Заголовки по умолчанию (объекты классов BasicNameValuePair или BasicHeader)

Link copied to clipboard
private var deserializeObjectMapper: JsonMapper?
Link copied to clipboard
private var host: String

Ссылка на сервис

Link copied to clipboard
private var httpClientBuilderFunc: (HttpClientBuilder) -> HttpClientBuilder?
Link copied to clipboard
private val jsonTypes: List<String>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private var serializeObjectMapper: JsonMapper?
Link copied to clipboard
private var sslContext: SSLContext?
Link copied to clipboard

Доверять всем (в т.ч. непроверенным) сертификатам

Link copied to clipboard

Доверять самозаверенным сертификатам

Link copied to clipboard

Использовать настройку MapperFeature.USE_STD_BEAN_NAMING для сериализации

Link copied to clipboard
private val xmlTypes: List<String>

Functions

Link copied to clipboard
protected fun createContentDispositionHeader(file: File, charset: Charset = StandardCharsets.UTF_8, locale: String = ""): BasicHeader

Создание заголовка "Content-Disposition".

Link copied to clipboard
private fun getFileFromResponse(response: HttpResponse, content: ByteArray): File?
Link copied to clipboard
private fun getHttpClient(): CloseableHttpClient
Link copied to clipboard
private fun getLineFromResponse(response: CloseableHttpResponse, content: ByteArray, id: String, searchHtml: Boolean = true): String
Link copied to clipboard
private fun getLineOrFileFromResponse(response: CloseableHttpResponse, content: ByteArray, id: String): Pair<File?, String>
Link copied to clipboard
private fun getRequestHeaders(headers: List<NameValuePair>?): MutableList<NameValuePair>
Link copied to clipboard
private fun <T> getResponseObject(uri: URI, response: HttpResponse, responseStr: String, responseClass: Class<T>, needThrow: Boolean, id: String): T
Link copied to clipboard
private fun getTempFileName(): String
Link copied to clipboard
private fun getUri(method: String, params: List<NameValuePair>? = null): URI
Link copied to clipboard
private fun requestToString(request: Any?): String?
Link copied to clipboard
private fun searchHtmlFile(response: CloseableHttpResponse, line: String)
Link copied to clipboard
protected fun sendCustomRequest(method: String, requestBase: HttpRequestBase): RestResponse<*>
protected fun <T> sendCustomRequest(responseClass: Class<T>, method: String, requestBase: HttpRequestBase): RestResponse<T>
protected fun <T> sendCustomRequest(needThrow: Boolean, responseClass: Class<T>, method: String, requestBase: HttpRequestBase): RestResponse<T>

Отправка пользовательского запроса.

Link copied to clipboard
protected fun sendDeleteRequest(method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса delete и получение ответа в виде строки

protected fun <T> sendDeleteRequest(responseClass: Class<T>, method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса delete и получение ответа в виде объекта

protected fun <T> sendDeleteRequest(needThrow: Boolean, responseClass: Class<T>, method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса delete и получение ответа в виде объекта. При передаче true в параметр needThrow и возникновении ошибки выбрасывается исключение RestException. Метод используется для негативных проверок

Link copied to clipboard
protected fun sendGetRequest(method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса get и получение ответа в виде строки

protected fun <T> sendGetRequest(responseClass: Class<T>, method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса get и получение ответа в виде объекта

protected fun <T> sendGetRequest(needThrow: Boolean, responseClass: Class<T>, method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса get и получение ответа в виде объекта. При передаче true в параметр needThrow и возникновении ошибки выбрасывается исключение RestException. Метод используется для негативных проверок

Link copied to clipboard
protected fun sendHeadRequest(method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса head

Link copied to clipboard
private fun sendHttpMethodForHttpResponse(id: String, httpRequestBase: HttpRequestBase, headers: List<NameValuePair>?, needThrow: Boolean, request: String? = null): Pair<Duration, CloseableHttpResponse>
Link copied to clipboard
protected fun sendOptionsRequest(method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса options

Link copied to clipboard
protected fun sendPatchRequest(method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса patch

protected fun <T> sendPatchRequest(responseClass: Class<T>, method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса patch и получение ответа в виде объекта

protected fun <T> sendPatchRequest(needThrow: Boolean, responseClass: Class<T>, method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса patch и получение ответа в виде объекта. При передаче true в параметр needThrow и возникновении ошибки выбрасывается исключение RestException. Метод используется для негативных проверок

Link copied to clipboard
protected fun sendPostRequest(method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса post

protected fun <T> sendPostRequest(responseClass: Class<T>, method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса post и получение ответа в виде объекта RestResponse

protected fun <T> sendPostRequest(needThrow: Boolean, responseClass: Class<T>, method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса post и получение ответа в виде объекта RestResponse. При передаче не null в responseClass и true в параметр needThrow и возникновении ошибки выбрасывается исключение RestException. Метод используется для негативных проверок

Link copied to clipboard
protected fun sendPostRequestWithFormUrlencoded(method: String, data: List<NameValuePair>, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса post с типом form urlencoded

Link copied to clipboard
protected fun sendPostRequestWithMultipart(method: String, formData: List<NameValuePair>? = null, headers: List<NameValuePair>? = null, file: File? = null): RestResponse<*>

Отправка запроса post с составным типом содержимого

protected fun <T> sendPostRequestWithMultipart(responseClass: Class<T>, method: String, formData: List<NameValuePair>? = null, headers: List<NameValuePair>? = null, file: File? = null): RestResponse<T>

Отправка запроса post c составным типом содержимого и получение ответа в виде объекта

protected fun <T> sendPostRequestWithMultipart(needThrow: Boolean, responseClass: Class<T>, method: String, formData: List<NameValuePair>? = null, headers: List<NameValuePair>? = null, file: File? = null): RestResponse<T>

Отправка запроса post c составным типом содержимого и получение ответа в виде объекта. При передаче true в параметр needThrow и возникновении ошибки выбрасывается исключение RestException. Метод используется для негативных проверок

private fun sendPostWithFormUrlencodedForHttpResponse(id: String, uri: URI, data: List<NameValuePair>, headers: List<NameValuePair>?, needThrow: Boolean): Pair<Duration, CloseableHttpResponse>
Link copied to clipboard
private fun sendPostWithMultipartForHttpResponse(id: String, uri: URI, formData: List<NameValuePair>?, headers: List<NameValuePair>?, file: File?, needThrow: Boolean): Pair<Duration, CloseableHttpResponse>
Link copied to clipboard
protected fun sendPutRequest(method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<String>

Отправка запроса put и получение ответа в виде строки

protected fun <T> sendPutRequest(responseClass: Class<T>, method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса put и получение ответа в виде объекта RestResponse

protected fun <T> sendPutRequest(needThrow: Boolean, responseClass: Class<T>, method: String, request: Any? = null, headers: List<NameValuePair>? = null): RestResponse<T>

Отправка запроса put и получение ответа в виде объекта RestResponse. При передаче true в параметр needThrow и возникновении ошибки выбрасывается исключение RestException. Метод используется для негативных проверок

Link copied to clipboard
protected fun sendTraceRequest(method: String, queryParameters: List<NameValuePair>? = null, headers: List<NameValuePair>? = null): RestResponse<*>

Отправка запроса trace

Link copied to clipboard
fun setDeserializeJsonMapper(mapper: JsonMapper)

Использование своего JsonMapper (вместо стандартного) для десереализации Json

Link copied to clipboard
private fun setRequestHeaders(httpMethod: HttpRequestBase, headers: List<NameValuePair>?, id: String): Unit?
Link copied to clipboard
fun setSerializeJsonMapper(mapper: JsonMapper)

Использование своего JsonMapper (вместо стандартного) для сереализации объектов

Link copied to clipboard

Использование настройки trustAllCertificates

Link copied to clipboard

Использование настройки trustSelfSignedCertificates.

Link copied to clipboard

Использование настройки MapperFeature.USE_STD_BEAN_NAMING для сериализации

Link copied to clipboard

Выключение логирования содержимого запроса к методам типа POST, PUT, PATCH.